<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ERB::Util</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ERB::Util</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/actionpack/lib/action_view/template_handlers/erb_rb.html">
                vendor/rails/actionpack/lib/action_view/template_handlers/erb.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000177">html_escape</a>&nbsp;&nbsp;
      <a href="#M000179">j</a>&nbsp;&nbsp;
      <a href="#M000178">json_escape</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">HTML_ESCAPE</td>
          <td>=</td>
          <td class="context-item-value">{ '&amp;' =&gt; '&amp;amp;',  '&gt;' =&gt; '&amp;gt;',   '&lt;' =&gt; '&amp;lt;', '&quot;' =&gt; '&amp;quot;' }</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">JSON_ESCAPE</td>
          <td>=</td>
          <td class="context-item-value">{ '&amp;' =&gt; '\u0026', '&gt;' =&gt; '\u003E', '&lt;' =&gt; '\u003C' }</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000177" class="method-detail">
        <a name="M000177"></a>

        <div class="method-heading">
          <a href="#M000177" class="method-signature">
          <span class="method-name">html_escape</span><span class="method-args">(s)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A utility method for escaping HTML tag characters. This method is also
aliased as <tt>h</tt>.
</p>
<p>
In your ERb templates, use this method to escape any unsafe content. For
example:
</p>
<pre>
  &lt;%=h @person.name %&gt;
</pre>
<h4>Example:</h4>
<pre>
  puts html_escape(&quot;is a &gt; 0 &amp; a &lt; 10?&quot;)
  # =&gt; is a &amp;gt; 0 &amp;amp; a &amp;lt; 10?
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000177-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000177-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/template_handlers/erb.rb, line 17</span>
17:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">html_escape</span>(<span class="ruby-identifier">s</span>)
18:       <span class="ruby-identifier">s</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/[&amp;&quot;&gt;&lt;]/</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">special</span><span class="ruby-operator">|</span> <span class="ruby-constant">HTML_ESCAPE</span>[<span class="ruby-identifier">special</span>] }
19:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000179" class="method-detail">
        <a name="M000179"></a>

        <div class="method-heading">
          <span class="method-name">j</span><span class="method-args">(s)</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for <a href="Util.html#M000178">json_escape</a>
</p>
        </div>
      </div>

      <div id="method-M000178" class="method-detail">
        <a name="M000178"></a>

        <div class="method-heading">
          <a href="#M000178" class="method-signature">
          <span class="method-name">json_escape</span><span class="method-args">(s)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A utility method for escaping HTML entities in JSON strings. This method is
also aliased as <tt><a href="Util.html#M000179">j</a></tt>.
</p>
<p>
In your ERb templates, use this method to escape any HTML entities:
</p>
<pre>
  &lt;%=j @person.to_json %&gt;
</pre>
<h4>Example:</h4>
<pre>
  puts json_escape(&quot;is a &gt; 0 &amp; a &lt; 10?&quot;)
  # =&gt; is a \u003E 0 \u0026 a \u003C 10?
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000178-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000178-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/template_handlers/erb.rb, line 30</span>
30:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">json_escape</span>(<span class="ruby-identifier">s</span>)
31:       <span class="ruby-identifier">s</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/[&amp;&quot;&gt;&lt;]/</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">special</span><span class="ruby-operator">|</span> <span class="ruby-constant">JSON_ESCAPE</span>[<span class="ruby-identifier">special</span>] }
32:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>